import $http from '../../http/http.js'
import apiSetting from '../../http/apiSetting.js'
let dayjs = require('dayjs');
let app = getApp();
Page({
  data: {
    isShow: false,
    webUrl: ''
  },

  onLoad(query) {
    if (query.type == "H5") {
      this.enterWeb()
    } else {
      this.getQuickBIUrl(query)
    }
  },

  enterWeb() {
    let corpId = app.globalData.corpId
    let userId = app.globalData.userId
    let unionId = app.globalData.unionId
    let devCorpId = app.globalData.devCorpId
    // 线上地址
    let oauthCallback = encodeURIComponent("https://ioc.iot.aliyun.com/signing_h5?from=appx&corpId=" + corpId + "&userId=" + userId + "&devCorpId=" + devCorpId + "&unionId=" + unionId)
    // 预发地址
    let oauthCallbackTest = encodeURIComponent("https://pre-ioc.iot.aliyun.com/signing_h5?from=appx&corpId=" + corpId + "&userId=" + userId + "&devCorpId=" + devCorpId + "&unionId=" + unionId)
    this.setData({
      isShow: true,
      webUrl: "https://account.aliyun.com/login/m_login.htm?oauth_callback=" + oauthCallback
      // webUrl: "https://account.aliyun.com/login/m_login.htm?oauth_callback=" + oauthCallbackTest
    })
    console.log(this.data.webUrl)
  },

  getQuickBIUrl(query) {
    let that = this
    $http(apiSetting.quickBIUrl, {
      type: query.type
    }).then((data) => {
      that.setData({
        isShow: true,
        webUrl: data.result
      })
      setTimeout(() => {
        dd.setNavigationBar({
          title: query.title
        })
        console.log(query.title)
      }, 2000);
    })
  }
});
